package com.zxy.supplier_system.server.entity

import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import org.hibernate.annotations.DynamicInsert
import org.hibernate.annotations.DynamicUpdate
import java.math.BigDecimal

@Entity
@DynamicUpdate
@DynamicInsert
class ProcurementReturnItem {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Int?=null

    @ManyToOne(optional = false)
    @JoinColumn
    lateinit var goods: Goods

    @ManyToOne(optional = true)
    @JoinColumn(nullable = true)
    var subGoods: SubGoods? = null

    @Column(nullable = false)
    var amount: Int = 0

    @ManyToOne(optional = false)
    @JoinColumn(nullable = false)
    lateinit var procurementReturn: ProcurementReturn

    var sequence: Int = 0

    /**
     * 退货价格
     */
    lateinit var price: BigDecimal

    var note:String? = null

}

val List<ProcurementReturnItem>.nextSequence: Int
    get() = this.maxOfOrNull {
        it.sequence
    }?.plus(1)?:0